package resource;

import java.io.IOException;
import java.io.InputStream;

/**
 * Created by inuyasha on 18-3-22.
 */
public class ClassPathResource implements Resource {

    private String path;

    private ClassLoader classLoader;

    public ClassPathResource(String path) {
        this(path, (ClassLoader)null);
    }

    public ClassPathResource(String path,ClassLoader classLoader){
        this.path = path;
        this.classLoader = classLoader == null ? Thread.currentThread().getContextClassLoader() : classLoader;
    }

    public InputStream getInputStream() throws IOException {
        return classLoader.getResourceAsStream(path);
    }
}
